package gc3d.gridspring;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author Pierrick
 *
 */
public class ProcReceiver implements Runnable {
	private InputStream is;
	public ProcReceiver(InputStream is) {
		this.is = is;
	}

	/**
	 * we have to read the buffer
	 * to do not get pipe overflow (make the pipe full)
	 * use: new Thread(new ProcReceiver(p.getInputStream())).start();
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		try {
			String buff;
			while ((buff = br.readLine()) != null) {
				if (buff.indexOf("Error") != -1) {
					System.out.println("[ERROR][ProcReceiver] "+buff);
				}
			}
			//while (br.readLine() != null);
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
